<template>
  <!-- 服务配置中心 -->
  <div style="padding: 20px">
    <el-form inline :model="form" ref="form" label-width="100px" size="mini">
      <el-form-item label="模块名称" prop="pivasName">
        <el-input
          placeholder="请输入模块名称"
          v-model="form.pivasName"
        ></el-input>
      </el-form-item>
      <el-button
        type="primary"
        size="mini"
        icon="el-icon-search"
        @click="handleQuery"
        >搜索</el-button
      >
      <el-button
        type="primary"
        plain
        icon="el-icon-plus"
        size="mini"
        @click="handleAdd"
        >新增</el-button
      >
      <el-button size="mini" icon="el-icon-refresh" @click="resetForm('form')"
        >重置</el-button
      >
    </el-form>
    <el-table :header-cell-style="thaderBack" :data="tableData">
      <el-table-column label="序号" width="80" align="center">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="pivasName" label="模块名称" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="pivasKey" label="类型" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="pivasIpurl" label="IP地址" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="pivasPort" label="端口" show-overflow-tooltip>
      </el-table-column>
      <el-table-column
        label="操作"
        align="left"
        class-name="small-padding fixed-width"
        min-width="50"
      >
        <template slot-scope="scope">
          <el-button type="text" size="mini" @click="handleUpdate(scope.row)"
            ><i class="el-icon-edit"></i>编辑</el-button
          >
          <el-button type="text" size="mini" @click="handleDelete(scope.row)"
            ><i class="el-icon-delete"></i>删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="config.page"
      :page-size="config.limit"
      layout="total,prev, pager, next, jumper"
      :total="total"
      class="pager"
    ></el-pagination>
    <el-dialog
      width="30%"
      :title="statusType === 'add' ? '新增' : '编辑'"
      :visible.sync="isShow"
    >
      <el-form
        ref="FormDetails"
        :model="FormDetails"
        label-width="80px"
        :rules="rules"
      >
        <el-row>
          <el-col :span="24">
            <el-form-item label="模块名称" prop="pivasName">
              <el-input
                v-model.trim="FormDetails.pivasName"
                placeholder="请输入模块名称"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="类型" prop="pivasKey">
              <el-select
                v-model="FormDetails.pivasKey"
                placeholder="请选择类型"
                style="width: 100%"
              >
                <el-option label="push推流" value="push"></el-option>
                <el-option label="websocket" value="websocket"></el-option>
                <el-option label="geoserver" value="geoserver"></el-option>
                <el-option label="自动化" value="automate"></el-option>
                <el-option label="rtmp拉流" value="rtmp"></el-option>
                <el-option label="双预控" value="syk"></el-option>
                <el-option label="AI视频" value="aimanage"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="IP地址" prop="pivasIpurl">
              <el-input
                v-model.trim="FormDetails.pivasIpurl"
                placeholder="请输入IP地址"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="端口号" prop="pivasPort">
              <el-input
                v-model.trim="FormDetails.pivasPort"
                placeholder="请输入端口号"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="账号" prop="pivasAccount">
              <el-input
                v-model.trim="FormDetails.pivasAccount"
                placeholder="请输入账号"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="密码" prop="pivasPassword">
              <el-input
                v-model.trim="FormDetails.pivasPassword"
                placeholder="请输入密码"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer" align="center">
        <el-button type="primary" @click="submitSend">确 定</el-button>
        <el-button @click="closeDetails" type="button">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { communal } from '@/api/common.js'
export default {
  mixins: [communal],
  data() {
    return {
      url: '/xbtPivas/list',
      addUrl: '/xbtPivas/add',
      editUrl: '/xbtPivas/edit',
      tableData: [],
      form: {
        pivasName: null
      },
      FormDetails: {
        pivasName: null,
        pivasKey: null,
        pivasIpurl: null,
        pivasPort: null,
        pivasAccount: null,
        pivasPassword: null
      },
      rules: {
        pivasName: [
          { required: true, message: '请输入模块名称', trigger: 'blur' },
          { min: 2, max: 10, message: '长度在 2 到 10 个字符', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    handleUpdate(row) {
      this.resetFormDetails('FormDetails')
      this.$http.get('/xbtPivas/detail?pivasId=' + row.pivasId).then(res => {
        if (res.code === 200) {
          this.FormDetails = res.data
          this.statusType = 'edit'
          this.isShow = true
        }
      })
    },
    handleDelete(row) {
      this.$confirm('是否确认删除?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.$http
            .post('/xbtPivas/del?pivasIds=' + row.pivasId)
            .then(response => {
              if (response.code === 200) {
                this.$message({
                  type: 'success',
                  message: '删除成功！'
                })
                this.config.page = 1
                this.getList()
              }
            })
        })
        .catch(function() {})
    }
  },
  created() {}
}
</script>

<style lang="scss" scoped></style>
